package com.itheima.controller;

import com.itheima.pojo.SmsHomeBrand;
import com.itheima.service.SmsHomeBrandService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/brand")
public class SmsHomeBrandController {
    @Autowired
    private SmsHomeBrandService smsHomeBrandService;
    /**
     * 添加首页推荐品牌
     * @param homeBrandList
     * @return
     */
    @PostMapping("create")
    public Result create(@RequestBody List<SmsHomeBrand> homeBrandList){
        smsHomeBrandService.create(homeBrandList);
        return Result.success(null);
    }

    /**
     * 批量删除推荐品牌
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public Result deleteByIds(@RequestParam List<Integer> ids){
        smsHomeBrandService.deleteByIds(ids);
        return Result.success(null);
    }

    /**
     * 分页查询推荐品牌
     * @param brandName
     * @param recommendStatus
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public Result list(String brandName,Integer recommendStatus,
                       @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
        PageResultVo resultVo=smsHomeBrandService.list(brandName,recommendStatus,pageNum,pageSize);
        return Result.success(resultVo);
    }

    /**
     * 批量修改推荐品牌状态
     * @param recommendStatus
     * @param ids
     * @return
     */
    @PostMapping("update/recommendStatus")
    public Result updateStatus(@RequestParam Integer recommendStatus,@RequestParam List<Integer> ids){
        smsHomeBrandService.updateStatus(recommendStatus,ids);
        return Result.success(null);
    }

    /**
     * 修改推荐品牌排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("update/sort/{id}")
    public Result updateSortById(@PathVariable("id") Integer id,@RequestParam Integer sort){
        smsHomeBrandService.updateSortById(id,sort);
        return Result.success(null);
    }

}
